#############################################################################
#Yuhua Wang#
#The Rise and Fall of Imperial China: The Social Origins of State Development#
#Princeton University Press, 2022#
############################################################################

############################################################################
#Chapter 3#
############################################################################


######################################
#Figure 3.1: Number of Registered Households (620–780)#
######################################

rm(list = ls())
library(foreign) 
library(ggplot2) 
require(ggplot2)
library(ggrepel) 
library(plyr)
require(scales)
require(gridExtra)

#Change this to your local directory#

setwd("/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Chapter 3/data/")

tanghousehold <- read.dta("tang household.dta")

household <- ggplot(tanghousehold[!is.na(tanghousehold$household),], aes(year,household)) + 
  geom_point() +
  geom_line(size=1)+
  scale_x_continuous(name="Year", limits=c(590,800), breaks=c(600,650,700,750,800)) +
  scale_y_continuous(name="Registered Households (millions)", limits=c(1,10),breaks=c(1,2,3,4,5,6,7,8,9,10))+
  theme(legend.position="none")+
  theme_bw()+
  theme(axis.text.x = element_text(color = "grey20", size = 12, family="Times"),
        axis.text.y = element_text(color = "grey20", size = 12, family="Times"),  
        axis.title.x = element_text(color = "grey20", size = 15, family="Times"),
        axis.title.y = element_text(color = "grey20", size = 15, family="Times"))+
  geom_vline(xintercept = 755,color="black",linetype="dashed")+
  geom_vline(xintercept = 763,color="black",linetype="dashed")+
  annotate(geom="text", x = 785, y=6, label = "An Lushan",size=3, family="Times",fontface =2)+
  annotate(geom="text", x = 785, y=5.5, label = "Rebellion", size=3, family="Times",fontface =2)

household
